Grupo 3 - Código da Aplicação Python 1/2015
MAIN ############################################################################ # -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'menuUI2.ui' # # Created: Fri Jun 19 16:31:35 2015 # by: PyQt4 UI code generator 4.10.4 # # WARNING! All changes made in this file will be lost! from PyQt4 import QtCore, QtGui from buscar import Buscador try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: def _fromUtf8(s): return s try: _encoding = QtGui.QApplication.UnicodeUTF8 def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig, _encoding) except AttributeError: def _translate(context, text, disambig): return QtGui.QApplication.translate(context, text, disambig) ################ ############### ############### ############### ########### # Janela principal class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8("MainWindow")) MainWindow.resize(717, 627) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(_fromUtf8("imagens/twB5.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) MainWindow.setWindowIcon(icon) MainWindow.setStyleSheet(_fromUtf8("background-image: url(:/background/imagens/bk4.png);")) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName(_fromUtf8("centralwidget")) self.gridLayout_2 = QtGui.QGridLayout(self.centralwidget) self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2")) self.gridLayout_5 = QtGui.QGridLayout() self.gridLayout_5.setObjectName(_fromUtf8("gridLayout_5")) self.plainTextEdit = QtGui.QPlainTextEdit(self.centralwidget) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(183, 209, 236)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(183, 209, 236)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(159, 158, 158)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush) self.plainTextEdit.setPalette(palette) self.plainTextEdit.setFrameShape(QtGui.QFrame.StyledPanel) self.plainTextEdit.setReadOnly(True) self.plainTextEdit.setObjectName(_fromUtf8("plainTextEdit")) self.gridLayout_5.addWidget(self.plainTextEdit, 0, 0, 1, 1) spacerItem = QtGui.QSpacerItem(280, 20, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum) self.gridLayout_5.addItem(spacerItem, 1, 0, 1, 1) self.gridLayout_2.addLayout(self.gridLayout_5, 0, 2, 5, 1) self.gridLayout_6 = QtGui.QGridLayout() self.gridLayout_6.setObjectName(_fromUtf8("gridLayout_6")) self.groupBox = QtGui.QGroupBox(self.centralwidget) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(203, 203, 203, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(182, 240, 214)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Highlight, brush) brush = QtGui.QBrush(QtGui.QColor(203, 203, 203, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(182, 240, 214)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Highlight, brush) brush = QtGui.QBrush(QtGui.QColor(159, 158, 158)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(240, 240, 240)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Highlight, brush) self.groupBox.setPalette(palette) self.groupBox.setAutoFillBackground(False) self.groupBox.setFlat(False) self.groupBox.setObjectName(_fromUtf8("groupBox")) self.gridLayout = QtGui.QGridLayout(self.groupBox) self.gridLayout.setObjectName(_fromUtf8("gridLayout")) self.opcaoPesquisaNome = QtGui.QRadioButton(self.groupBox) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(8, 189, 255, 150)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(8, 189, 255, 150)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(159, 158, 158)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) self.opcaoPesquisaNome.setPalette(palette) self.opcaoPesquisaNome.setChecked(True) self.opcaoPesquisaNome.setObjectName(_fromUtf8("opcaoPesquisaNome")) self.gridLayout.addWidget(self.opcaoPesquisaNome, 1, 0, 1, 1) self.opcaoPesquisaTweet = QtGui.QRadioButton(self.groupBox) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(15, 163, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(20, 114, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(15, 163, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(20, 114, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(159, 158, 158)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(159, 158, 158)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush) self.opcaoPesquisaTweet.setPalette(palette) self.opcaoPesquisaTweet.setObjectName(_fromUtf8("opcaoPesquisaTweet")) self.gridLayout.addWidget(self.opcaoPesquisaTweet, 2, 0, 1, 1) self.botaoPesquisa = QtGui.QPushButton(self.groupBox) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(59, 53, 255, 160)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(59, 53, 255, 160)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(159, 158, 158)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush) self.botaoPesquisa.setPalette(palette) font = QtGui.QFont() font.setFamily(_fromUtf8("Ubuntu")) font.setBold(True) font.setItalic(False) font.setUnderline(False) font.setWeight(75) font.setStrikeOut(False) font.setKerning(True) self.botaoPesquisa.setFont(font) self.botaoPesquisa.setMouseTracking(False) self.botaoPesquisa.setAutoFillBackground(False) self.botaoPesquisa.setDefault(False) self.botaoPesquisa.setFlat(False) self.botaoPesquisa.setObjectName(_fromUtf8("botaoPesquisa")) self.gridLayout.addWidget(self.botaoPesquisa, 2, 1, 1, 1) self.botaoPesquisa.clicked.connect(self.pesquisar) #################### Pesquisa self.gridLayout_6.addWidget(self.groupBox, 0, 0, 1, 1) self.gridLayout_2.addLayout(self.gridLayout_6, 1, 0, 1, 1) self.verticalLayout = QtGui.QVBoxLayout() self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.lineEdit = QtGui.QLineEdit(self.centralwidget) self.lineEdit.setEnabled(True) self.lineEdit.setCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor)) self.lineEdit.setAutoFillBackground(False) self.lineEdit.setInputMethodHints(QtCore.Qt.ImhNone) self.lineEdit.setFrame(True) self.lineEdit.setEchoMode(QtGui.QLineEdit.Normal) self.lineEdit.setCursorMoveStyle(QtCore.Qt.LogicalMoveStyle) self.lineEdit.setObjectName(_fromUtf8("lineEdit")) self.verticalLayout.addWidget(self.lineEdit) self.gridLayout_2.addLayout(self.verticalLayout, 0, 0, 1, 1) self.gridLayout_4 = QtGui.QGridLayout() self.gridLayout_4.setObjectName(_fromUtf8("gridLayout_4")) spacerItem1 = QtGui.QSpacerItem(80, 20, QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Minimum) self.gridLayout_4.addItem(spacerItem1, 0, 0, 1, 1) self.botaoSair = QtGui.QPushButton(self.centralwidget) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(206, 206, 206)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(206, 206, 206)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(159, 158, 158)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush) self.botaoSair.setPalette(palette) self.botaoSair.setCursor(QtGui.QCursor(QtCore.Qt.ForbiddenCursor)) self.botaoSair.setAutoDefault(False) self.botaoSair.setDefault(False) self.botaoSair.setFlat(False) self.botaoSair.setObjectName(_fromUtf8("botaoSair")) self.gridLayout_4.addWidget(self.botaoSair, 0, 1, 1, 1) self.botaoSair.clicked.connect(QtCore.QCoreApplication.instance().quit) ################## SAIR self.gridLayout_2.addLayout(self.gridLayout_4, 7, 2, 1, 1) self.gridLayout_3 = QtGui.QGridLayout() self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3")) spacerItem2 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.gridLayout_3.addItem(spacerItem2, 2, 1, 1, 1) self.verticalLayout_2 = QtGui.QVBoxLayout() self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2")) self.PassaroT = QtGui.QGraphicsView(self.centralwidget) self.PassaroT.setEnabled(True) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.MinimumExpanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.PassaroT.sizePolicy().hasHeightForWidth()) self.PassaroT.setSizePolicy(sizePolicy) self.PassaroT.setAcceptDrops(True) self.PassaroT.setAutoFillBackground(False) self.PassaroT.setStyleSheet(_fromUtf8("QGraphicsView{\n" " background-image: url(:/bbird/imagens/twB5.png);\n" "}")) self.PassaroT.setFrameShape(QtGui.QFrame.NoFrame) self.PassaroT.setFrameShadow(QtGui.QFrame.Sunken) self.PassaroT.setAlignment(QtCore.Qt.AlignCenter) self.PassaroT.setObjectName(_fromUtf8("PassaroT")) self.verticalLayout_2.addWidget(self.PassaroT) self.gridLayout_3.addLayout(self.verticalLayout_2, 3, 1, 1, 1) spacerItem3 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum) self.gridLayout_3.addItem(spacerItem3, 1, 2, 1, 1) spacerItem4 = QtGui.QSpacerItem(20, 237, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed) self.gridLayout_3.addItem(spacerItem4, 3, 2, 1, 1) self.botaoResultados = QtGui.QPushButton(self.centralwidget) self.botaoResultados.setEnabled(True) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ToolTipText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipText, brush) brush = QtGui.QBrush(QtGui.QColor(88, 33, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipText, brush) self.botaoResultados.setPalette(palette) self.botaoResultados.setFlat(False) self.botaoResultados.setObjectName(_fromUtf8("botaoResultados")) self.gridLayout_3.addWidget(self.botaoResultados, 1, 1, 1, 1) self.botaoResultados.clicked.connect(self.imprimirBD) #################### RESULTADOS BD self.groupBox_2 = QtGui.QGroupBox(self.centralwidget) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(193, 193, 193)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(193, 193, 193)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(159, 158, 158)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) self.groupBox_2.setPalette(palette) self.groupBox_2.setObjectName(_fromUtf8("groupBox_2")) self.horizontalLayout = QtGui.QHBoxLayout(self.groupBox_2) self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) self.spinBox = QtGui.QSpinBox(self.groupBox_2) self.spinBox.setMinimum(1) self.spinBox.setMaximum(1000) self.spinBox.setProperty("value", 15) self.spinBox.setObjectName(_fromUtf8("spinBox")) self.horizontalLayout.addWidget(self.spinBox) spacerItem5 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem5) self.gridLayout_3.addWidget(self.groupBox_2, 0, 1, 1, 2) self.gridLayout_2.addLayout(self.gridLayout_3, 4, 0, 1, 1) spacerItem6 = QtGui.QSpacerItem(0, 0, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.gridLayout_2.addItem(spacerItem6, 1, 1, 1, 1) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 717, 25)) self.menubar.setObjectName(_fromUtf8("menubar")) MainWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName(_fromUtf8("statusbar")) MainWindow.setStatusBar(self.statusbar) self.toolBar = QtGui.QToolBar(MainWindow) self.toolBar.setObjectName(_fromUtf8("toolBar")) MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(_translate("MainWindow", "Twese", None)) self.groupBox.setTitle(_translate("MainWindow", "Pesquisar por:", None)) self.opcaoPesquisaNome.setText(_translate("MainWindow", "Nome", None)) self.opcaoPesquisaTweet.setText(_translate("MainWindow", "Tweet", None)) self.botaoPesquisa.setText(_translate("MainWindow", "Pesquisar", None)) self.botaoSair.setText(_translate("MainWindow", "Sair", None)) self.botaoResultados.setText(_translate("MainWindow", "Resultados no Banco de Dados", None)) self.groupBox_2.setTitle(_translate("MainWindow", "Quantidade de Resultados por pesquisa:", None)) self.toolBar.setWindowTitle(_translate("MainWindow", "toolBar", None)) # self.botaoResultados.clicked.connect(self.imprimirBD) #################### RESULTADOS BD # self.botaoSair.clicked.connect(QtCore.QCoreApplication.instance().quit) ################## SAIR # self.botaoPesquisa.clicked.connect(self.pesquisar) #################### Pesquisa def imprimirBD(self): pesquisarPor = self.lineEdit.text() from banco import ConexaoBanco as db with db("localhost","root","123","busca_twitter") as db: self.plainTextEdit.setPlainText( db.retorna_busca(pesquisarPor) ) def pesquisar(self): # Atribuimos a 'pesquisarPor' o que foi escrito pelo usuario para realizar a busca pesquisarPor = self.lineEdit.text() busca = Buscador() if self.opcaoPesquisaNome.isChecked(): #< Pesquisa por Nome self.plainTextEdit.setPlainText( busca.buscaUsuarios(pesquisarPor, self.spinBox.value()) ) else: #< Pesquisa por Tweet self.plainTextEdit.setPlainText( busca.buscaTweets(pesquisarPor, self.spinBox.value()) ) import imgres_rc if __name__ "__main__": import sys app = QtGui.QApplication(sys.argv) MainWindow = QtGui.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_()) Módulo de Usuários e Tweets class Tweet(object): def __init__(self): self.idAutor = 0 self.id = 0 self.local = "nao disponivel" self.tweet = "nao disponivel" class Usuario(object): def __init__(self): self.nome = "nao disponivel" self.id = 0 self.usu = "nao disponivel" self.local = "nao disponivel" Módulo de busca import tweepy from LP_tweet_e_usuario import Usuario from LP_tweet_e_usuario import Tweet from banco import ConexaoBanco as db #para criar um objeto de busca, basta fazer obj = Buscador() #para realizar uma busca por usuario, obj.buscaUsuarios("valor") #para realizar uma busca por tweet, obj.buscaTweets("valor") #a busca automaticamente chama a database class Buscador(): def __init__(self) : #define globais global api global auth #inicializa a variavel query_dict # query_dict = {} ##define os tokens para autenticacao consumer_token = 'VQT9g3535sl0DmTAlwokMKgQE' consumer_secret = 'n7zka46UHN5zI4EfET7mPS9zlgEvbCVQ7bdWmBZi6jmsRCFnDT' access_token = '23691015-pVbwJFLg5TwF3TuZZgE0PvjfECsdRiFmzN7W1BeGr' access_secret = 'LtRjFZEIWowjFwK7WH693MXxKVWAVcmSAilgJXipF0Gi6' ##autentica a sessao auth = tweepy.OAuthHandler(consumer_token, consumer_secret) auth.set_access_token(access_token, access_secret) api = tweepy.API(auth) #busca usuarios, de acordo com a query entrada. nao ha retorno, e sim uma call direta ao modulo de database def buscaUsuarios (self, query, amount): from banco import ConexaoBanco as db #inicia a lista de Usuarios result_list = [] retorno = "" for user in tweepy.Cursor(api.search_users, q = query, count= 25, result_type="recent", include_entities = True).items() : #instancia um objeto Usuario usuario = Usuario() #da set nos parametros usuario.id = user._json'id' #eh int usuario.usu = user._json'screen_name' usuario.nome = user._json'name' usuario.local = user._json'location' #adiciona na lista de resultados jah parseado retorno = str(usuario.id) + "\n@" + usuario.usu + '\n' + usuario.nome + '\n' + usuario.local + '\n\n' + retorno result_list.append(usuario) amount = amount - 1 if amount 0: break with db("localhost","root","123","busca_twitter") as db: db.nova_busca(query,"USUARIO") db.inserir_usuarios(result_list) db.salvar() return retorno #TO-DO: colocar as funcoes do vitor aqui, mandando o query_dict #busca amount tweets com a query fornecida def buscaTweets (self, query, amount) : from banco import ConexaoBanco as db #inicia a lista de Tweet result_list = [] retorno = "" #popula a lista com o resultado for result in tweepy.Cursor(api.search, q= query, count=100, result_type="recent", include_entities=True).items(): #cria um objeto Tweet tweet = Tweet() tweet.idAutor = result._json'user''id' tweet.id = result._json'id' tweet.local = result._json'user''location' tweet.tweet = result._json'text' result_list.append(tweet) retorno = str(tweet.id) + "\nid autor: " + str(tweet.idAutor) + "\nLocalizacao: " + tweet.local + "\ntweet: \"" + tweet.tweet + "\"\n\n" + retorno amount = amount - 1 if (amount 0) : break with db("localhost","root","123","busca_twitter") as db: db.nova_busca(query,"TWEET") db.inserir_tweets(result_list) db.salvar() return retorno Módulo do Banco de Dados MySql # -*- coding: utf-8 -*- import MySQLdb as mysql # importando biblioteca MySQLdb class ConexaoBanco(object): def __init__(self,host,usuario,passwd,db): self._db = mysql.connect(host=host,user=usuario, passwd=passwd,db=db,charset='utf8') self._cursor = self._db.cursor(mysql.cursors.DictCursor) def __enter__(self): return self def __exit__(self,type,value,traceback): self._db.close() def salvar(self): self._db.commit() def retorna_busca(self,parametro): self._query = "SELECT * FROM busca WHERE busca.parametro = '%s'" % (parametro) retorno = "" self._cursor.execute(self._query) buscas = self._cursor.fetchall() for busca in buscas: if busca'tipo' 1: self._query = "SELECT * FROM tweet WHERE idBusca = %s" % busca'idBusca' self._cursor.execute(self._query) colunas = self._cursor.fetchall() for coluna in colunas: retorno = str(coluna'idTweet') + "\nid autor: " + str(coluna'idAutor') + "\nLocalizacao: " + coluna'local' + "\ntweet: \"" + coluna'mensagem' + "\"\n\n" + retorno else: self._query = "SELECT * FROM usuario WHERE idBusca = %s" % busca'idBusca' self._cursor.execute(self._query) colunas = self._cursor.fetchall() for coluna in colunas: retorno = str(coluna'idAutor') + "\n@" + coluna'usuario' + '\n' + coluna'nome' + '\n' + coluna'local' + '\n\n' + retorno return retorno def nova_busca(self,parametro,tipo): if tipo "USUARIO": self._tipo = 0 elif tipo "TWEET": self._tipo = 1 self._query = "INSERT INTO busca (parametro,tipo) VALUES ('%s',%s)" % (parametro,self._tipo) self._cursor.execute(self._query) self._id_busca = self._db.insert_id() def inserir_tweet(self,tweet): self._query = "INSERT INTO tweet (idTweet,idAutor,local,mensagem,idBusca) VALUES (%s,%s,'%s','%s',%s)" % (tweet.id , tweet.idAutor , tweet.local , tweet.tweet,self._id_busca) try: self._cursor.execute(self._query) except: pass def inserir_tweets(self,tweets): for tweet in tweets: self._query = "INSERT INTO tweet (idTweet,idAutor,local,mensagem,idBusca) VALUES (%s,%s,'%s','%s',%s)" % (tweet.id , tweet.idAutor , tweet.local , tweet.tweet,self._id_busca) try: self._cursor.execute(self._query) except: pass def inserir_usuario(self,usuario): self._query = "INSERT INTO usuario (nome,idAutor,usuario,local,idBusca) VALUES ('%s',%s,'%s','%s',%s)" % (usuario.nome,usuario.id,usuario.usu,usuario.local,self._id_busca) try: self._cursor.execute(self._query) except: pass def inserir_usuarios(self,usuarios): for usuario in usuarios: self._query = "INSERT INTO usuario (nome,idAutor,usuario,local,idBusca) VALUES ('%s',%s,'%s','%s',%s)" % (usuario.nome,usuario.id,usuario.usu,usuario.local,self._id_busca) try: self._cursor.execute(self._query) except: pass